{% extends "app/base_site.html" %}
{% block title %} {% if  "add" == handle %}添加{% else %}编辑{% endif %}行为算法 {% endblock title %}
{% block stylesheets %}
  {{ block.super }}
{% endblock stylesheets %}

{% block content %}

  <div class="right_col" role="main">
    <div class="">
      <div class="row">
        <div class="col-md-12 col-xs-12">
          <div class="x_panel">
            <div class="x_title">
                <h2>{% if  "add" == handle %}添加{% else %}编辑{% endif %}行为算法 <span id="top_msg">{{top_msg}}</span></h2>
              <div class="clearfix"></div>
            </div>
            <div class="x_content">
              <br>
              <form class="form-horizontal form-label-left"  method="post" enctype="multipart/form-data" data-parsley-validate  >

                     <input type="hidden" name="handle"  value="{{ handle }}">
                     <input type="hidden" name="code"  value="{{ behaviour.code }}">

                <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">算法编号 </label>
                  <div class="col-md-3 col-sm-3 col-xs-12">
                     <input type="text"  value="{{ behaviour.code }}" class="form-control" disabled="disabled">
                  </div>
                </div>


                  <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">算法名称 <span class="required">*</span></label>
              <div class="col-md-3 col-sm-3 col-xs-12">
                    <input type="text" name="name" value="{{ behaviour.name }}" required="required"  class="form-control">
                  </div>
                </div>
{% if "edit" == handle %}<input type="hidden" name="way_code" value="{{ behaviour.way_code }}">{% endif %}

               <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">请选择接入方式 <span class="required">*</span></label>
             <div class="col-md-3 col-sm-3 col-xs-12">
                    <select name="way_code" {% if "edit" == handle %}disabled="disabled"{% endif %} class="form-control">

                        <option value="0">请选择</option>
                        {% for way in behaviour_ways %}
                            {% if behaviour.way_code == way.code %}
                                <option selected value="{{ behaviour.way_code }}">{{ way.name }}</option>
                            {% else %}
                               <option value="{{ way.code }}">{{ way.name }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                  </div>
                </div>

               <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">接入参数 <span class="required">*</span>
                  </label>
                  <div class="col-md-9 col-sm-9 col-xs-12">
                    <textarea name="way_value" class="form-control" rows="2" placeholder="">{{ behaviour.way_value }}</textarea>
                  </div>
                </div>


                  <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">备注
                  </label>
                  <div class="col-md-9 col-sm-9 col-xs-12">
                    <textarea name="remark" class="form-control" rows="3" placeholder="">{{ behaviour.remark }}</textarea>
                  </div>
                </div>

                <div class="form-group">
                  <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
                    <button type="button" onclick="window.history.go(-1)" class="btn btn-primary">取消</button>
                    <button type="submit" class="btn btn-success">提交</button>
                  </div>
                </div>

              </form>
            </div>
          </div>
        </div>
      </div>

    </div>
  </div>
{% endblock content %}

{% block javascripts %}
  {{ block.super }}
<script>

let handle = "{{ handle }}";
let behaviour_code = "{{ behaviour.code }}";
let ele_input_name= $("input[name='name']");
let ele_select_way_code= $("select[name='way_code']");
let ele_textarea_way_value = $("textarea[name='way_value']");

$(document).ready(function () {
   $("form").submit(function () {

        if(ele_input_name.val().trim() === ""){
            myAlert("请输入算法名称","error");
            return false;
        }
        if(ele_select_way_code.val().trim()==="0"){
            myAlert("请选择接入方式","error");
            return false;
        }
       let way_value = ele_textarea_way_value.val().trim();
       if(way_value==="0" || way_value===""){
            myAlert("请输入接入参数","error");
            return false;
        }

   });
});

</script>

{% endblock javascripts %}
